package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.Article;
import com.briup.jz.bean.extend.ArticleExtend;
import com.briup.jz.service.IArticleService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="资讯公告信息")
@Validated
@RestController
@RequestMapping("/article")
public class ArticleController {
	@Autowired
	private IArticleService articleService;
	
	@ApiOperation("阅读文章")
	@GetMapping("read")
	public Message read(long id) {
	ArticleExtend article = articleService.read(id);
		return MessageUtil.success(article);
		
	}
	
	@ApiOperation(value="查询所有资讯公告")
	@GetMapping("query")
	public Message query(String title,String status,Long categoryId) {
	List<Article> list=articleService.query(title,status,categoryId);
		return MessageUtil.success(list);
	}
	
	@ApiOperation(value="级联查询所有资讯公告")
	@GetMapping("queryCascade")
	public Message queryCascade(String title,String status,Long categoryId) {
	List<ArticleExtend> list=articleService.queryCascade(title,status,categoryId);
		return MessageUtil.success(list);
	}
	
	@ApiOperation(value = "通过id删除")
	@GetMapping("deleteById")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
	})
	public Message deleteById(@NotNull Long id){
        articleService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
	
	 @ApiOperation(value = "保存或更新资讯公告信息")
	 @ApiImplicitParams({
		 @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
		 @ApiImplicitParam(name="title",value = "公告标题",paramType = "form",required = true),
		 @ApiImplicitParam(name="content",value = "公告内容",paramType = "form"),
         @ApiImplicitParam(name="publishTime",value = "发布时间",paramType = "form"),
         @ApiImplicitParam(name="readTimes",value = "阅读次数",paramType = "form"),
         @ApiImplicitParam(name="status",value = "状态",paramType = "form"),
         @ApiImplicitParam(name="thumpUp",value = "点赞量",paramType = "form"),
         @ApiImplicitParam(name="cover",value = "封面",paramType = "form"),
         @ApiImplicitParam(name="projectId",value = "项目id",paramType = "form"),
         @ApiImplicitParam(name="authorId",value = "作者id",paramType = "form"),
         @ApiImplicitParam(name="categoryId",value = "分类id",paramType = "form"),
         @ApiImplicitParam(name="componyId",value = "公司id",paramType = "form"),  
	 })
	 
	 @PostMapping("saveOrUpdate")
	 public Message saveOrUpdate(Article atricle){
	    	articleService.saveOrUpdate(atricle);
	        return MessageUtil.success("更新成功");
	    }
	 @ApiOperation(value = "级联查询学生风采")
		@GetMapping("cascadeFindAll")	
		public Message cascadeFindAll(){
	        articleService.cascadeFindAll();
	        return null;
	    }
	 
	 @ApiOperation(value = "修改风采状态")
		@PostMapping("changeStatus")
		@ApiImplicitParams({
			@ApiImplicitParam(name="id",value = "风采编号",paramType = "query", required=true),
			@ApiImplicitParam(name="status",value = "状态",paramType = "query", required=true),
		})
		public Message changeStatus(@NotNull String id,String status){
	        articleService.changeStatus(id,status);
	        return null;
	    }
	 
	 @ApiOperation(value = "将消息导入到Excel中")
		@GetMapping("download")
		public Message download(){
	        articleService.download();
	        return null;
	    }
	 
	 @ApiOperation(value = "分页获取所有推荐学生风采信息")
		@GetMapping("findAllRecommend")
		@ApiImplicitParams({
			@ApiImplicitParam(name="page",value = "当前页",paramType = "query", required=true),
			@ApiImplicitParam(name="pageSize",value = "每页大小",paramType = "query", required=true),
		})
		public Message findAllRecommend(@NotNull String page,String pageSize){
	        articleService.findAllRecommend(page,pageSize);
	        return null;
	    }
	 
	 @ApiOperation(value = "分页获取所有推荐学生风采信息")
		@GetMapping("findById")
		@ApiImplicitParams({
			@ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
			
		})
		public Message findById(@NotNull String id){
	        articleService.findById(id);
	        return MessageUtil.success("获取成功");
	    }
	 
	 @ApiOperation(value = "分页多条件获取学生风采信息")
	 @ApiImplicitParams({
		 @ApiImplicitParam(name="page",value = "当前页",paramType = "form",required = true),
		 @ApiImplicitParam(name="pageSize",value = "每页大小",paramType = "form",required = true),
		 @ApiImplicitParam(name="title",value = "学生风采标题",paramType = "form"),
         @ApiImplicitParam(name="status",value = "风采状态",paramType = "form"),
         @ApiImplicitParam(name="authorId",value = "作者id",paramType = "form"),
         @ApiImplicitParam(name="categoryId",value = "分类id",paramType = "form"),
        
	 })

	 @GetMapping("pageQuery")
	 public Message pageQuery(String page,String pageSize,String title,String status,String authorId,String categoryId){
	    	articleService.pageQuery(page,pageSize,title,status,authorId,categoryId);
	        return null;
	    }
}
